package roborally.model;

public enum Orientation {

	UP {
		public final long getRelativeCoordinatesX() {
			return 0;
		}
		
		public final long getRelativeCoordinatesY() {
			return -1;
		}
		
		public final int intValue() {
			return 0;
		}
	}, 
	RIGHT {
		public final long getRelativeCoordinatesX() {
			return 1;
		}
		
		public final long getRelativeCoordinatesY() {
			return 0;
		}
		
		public final int intValue() {
			return 1;
		}
	},
	DOWN {
		public final long getRelativeCoordinatesX() {
			return 0;
		}
		
		public final long getRelativeCoordinatesY() {
			return 1;
		}
		
		public final int intValue() {
			return 2;
		}
	},
	LEFT{
		public final long getRelativeCoordinatesX() {
			return -1;
		}
		
		public final long getRelativeCoordinatesY() {
			return 0;
		}
		
		public final int intValue() {
			return 3;
		}
	};
	
	public abstract long getRelativeCoordinatesX();
	public abstract long getRelativeCoordinatesY();
	public abstract int intValue();
	
	public Orientation turn90(Direction direction) {
		long newX = this.getRelativeCoordinatesY()*direction.getTurnValue();
		long newY = -this.getRelativeCoordinatesX()*direction.getTurnValue();
		for (Orientation ori : Orientation.values()){
			if(newX == ori.getRelativeCoordinatesX() && newY == ori.getRelativeCoordinatesY()) {
				return ori;
			}
		}
		return this; //if not valid, do not change direction;
	}
	
	public Orientation turn90Clockwise() {
		
		return turn90(Direction.CLOCKWISE);
	}
	
	public Orientation turn90CounterClockwise() {
		
		return turn90(Direction.COUNTERCLOCKWISE);
	}
	
}
